package com.extra_archive.project.iisu.view 
{
	import com.extra_archive.framework.core.mvc.controller.IController;
	import com.extra_archive.framework.core.mvc.model.IModel;
	import com.extra_archive.framework.core.mvc.view.ComponentView;
	import com.extra_archive.project.iisu.model.ARModel;
	import com.extra_archive.project.iisu.model.ARModelEvent;
	import com.extra_archive.project.iisu.view.detail.ARDetailView;
	import com.extra_archive.project.iisu.view.list.ARListCarouselView;

	/**
	 * @author implict
	 */
	public class ARMediatorView extends BasicMediatorView 
	{
		private var _listView : IARState;
		private var _detailView : IARState;
		
		private var _state : IARState;
		
		public function ARMediatorView(model : IModel = null, controller : IController = null)
		{
			super(model, controller);
		}

		//--------------------------------------------------------------------------
		//
		//    Public Methods
		//
		//--------------------------------------------------------------------------
		
		override public function initialize() : void 
		{
			super.initialize();
			
			createListView();
			createDetailView();
			
			setState(_listView);
			
			ARModel(_model).gesture.addEventListener(ARModelEvent.LIST_TO_DETAIL, onListToDetail);
			ARModel(_model).gesture.addEventListener(ARModelEvent.DETAIL_TO_LIST, onDetailToList);
		}
		
		public function setState(state : IARState) : void
		{
			if (_state)
			{
				_state.kill();
				removeChild(ComponentView(_state));
			 	removeComponent(_state);
			}	
			 state.live();
			 addChild(ComponentView(state));
			 addComponent(state);
			 
			 _state = state;
		}
		
		override public function toString() : String 
		{
			return "com.dstrict.project.softkinetic.view.ARMediatorView";
		}
		
		//--------------------------------------------------------------------------
		//
		//    Event Listeners
		//
		//--------------------------------------------------------------------------
		
		private function onDetailToList(event : ARModelEvent) : void 
		{
			setState(_listView);
		}

		private function onListToDetail(event : ARModelEvent) : void 
		{
			setState(_detailView);
		}
		
		//--------------------------------------------------------------------------
		//
		//    Private Methods
		//
		//--------------------------------------------------------------------------
		
		private function createListView() : void 
		{
			//_listView = new ARListVerticalView(_model, _controller);
			_listView = new ARListCarouselView(_model, _controller);
		}
		
		private function createDetailView() : void 
		{
			_detailView = new ARDetailView(_model, _controller);
		}
	}
}
